<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<!--    ________________________________________________________________

           File: xml2html.xsl (this version of xml2html.xsl is ONLY for
                               use with Xsltproc!)
        Version: 1.02
           Date: 2002-August-14
         Author: Michael Auth; 
                 Developed developed at the Department of Linguistics
                 of the University of Tuebingen, Germany.
        
        Copyright (C) 2002 Michael Auth
        ________________________________________________________________

        This stylefile is distributed under the terms of the
        GNU GENERAL PUBLIC LICENSE:
        This program is free software; you can redistribute it and/or
        modify it under the terms of the GNU General Public License
        as published by the Free Software Foundation; either version 2
        of the License, or (at your option) any later version.
        
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
        See the file COPYING.txt (which comes along with the package file
        xml2html.zip) for the full liscence text about the terms and
        conditions for copying, distributing and modification.
        ________________________________________________________________

        
        Info: This stylesheet does...
        *****************************
        - ... generate a complete list of all publications
          presented in your XML-file.
          The generated HTML-file also contains a link to
          another HTML file, showing all different categories (see below).
        - ... generate one HTML file, where all thematic categories are
          represented and linked to their HTML representation.

        DO NOT MODIFY THIS STYLESHEET,
        IN CASE OF MODIFYING THE CATEGORIES AND OTHER VARIABLES
        SEE DEFINITIONS.XML!
-->


<!-- Import the stylesheet "xml2bib.xsl" that handles the transformation
     from XML back to BibTeX.
     This stylesheet is used to generate the BibTeX-HTML files
     showing each entry in BibTeX style in a single HTML file: -->
    <xsl:import href="xml2bib.xsl"/>

<!-- Set the output options of the result tree: -->
    <xsl:output method="html" encoding="{document('definitions.xml')//charset}" indent="yes"/>
    <xsl:output method="html" encoding="{document('definitions.xml')//charset}" indent="yes" name="htmlFormat"/>


<!-- Save the root node of the basic XML file (so it won't mix up
     with "definitions.xml", which will be included later): -->
    <xsl:variable name="main" select="/"/>

<!-- Set the bibhtml_path parameter:
     This parameter stores the bib_html path (the path were all
     BibTeX-HTML files will be stored to -->
    <xsl:variable name="bibhtml_path" select="'bibhtml/'"/>
   

<!-- ##########################################################################
                            Main Template - Start Parsing
     ##########################################################################
-->
<xsl:template match="/">
    <!-- Step #1:
         +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
         Generate one single HTML file presenting ALL BibTeX-entries
         from the XML file: (obligatory) -->
        <xsl:call-template name="gen_list"/>
    
    <!-- Step #2:
         +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
         Check if there are any categories set in definitions.xml;
         if yes - Proceed all Categories: (optional) -->
        <xsl:if test="document('definitions.xml')//category">
            <!-- call main-loop: process all entries from the
                 definition-section in the XML file -->
            <xsl:call-template name="gen_cat_sorted"/>
            <!-- generate HTML file presenting all subjects in a table
                 and link them with their corresponding HTML files: -->
            <xsl:call-template name="gen_overview"/>
        </xsl:if>
</xsl:template>
<!-- ##################### Main Template - End - ########################## -->



<!-- ########################### List Template ################################
        name: gen_list
        does ... generate one single HTML-file presenting ALL publications
     ##########################################################################
-->
<xsl:template name="gen_list">
    <!-- use <xsl:document> to force output to an external html-file: -->
    <xsl:document href="list.html" format="htmlFormat">   
        <html> 
        <head>
            <!-- write: TitleBar + Meta-Tags + CSS-Definitions -->
            <xsl:call-template name="html_head"/>
        </head>
        <body>
            <!-- set the header depending on the thematic category: -->
            <xsl:call-template name="write_head">
                <xsl:with-param name="header" select="document('definitions.xml')//head_list"/>
            </xsl:call-template>
            <!-- choose ALL entries  -->
            <xsl:apply-templates select="bibliography"/>
        </body>
        </html>
    </xsl:document>
</xsl:template>
<!-- ##################### List Template - End - ########################## -->




<!-- ######################### Categories Template ############################
        name: gen_cat_sorted
        does ... generate different Category-sorted HTML-files
     ##########################################################################
-->
<xsl:template name="gen_cat_sorted">
    
    <!-- process all subjects of every single category: -->
    <xsl:for-each select="document('definitions.xml')//categories/descendant::*">
        <!-- set variables: -->
        <xsl:variable name="catid_name"> <!-- (e.g. 'LI') -->
            <xsl:value-of select="@catid"/>
        </xsl:variable>
        <xsl:variable name="catid"> <!-- (e.g. 'catid2') -->
            <xsl:text>catid</xsl:text>
            <!-- get catid_number from the id attribute
                 ('1' if one char; '2' if three chars (e.g. 1.1); ...) -->
            <xsl:value-of select="string-length(translate(string(@id), '.', ''))"/>
        </xsl:variable>
        <xsl:variable name="header"> <!-- (e.g. 'Linguistics') -->
            <xsl:value-of select="@name"/> 
        </xsl:variable>
        <xsl:variable name="level">
            <xsl:value-of select="@id"/> <!-- (e.g. '1.1.6') -->
        </xsl:variable>
        
        <!-- generate HTML-file(s): -->
        <xsl:document href="{$catid_name}.html" format="htmlFormat">
            <html> 
            <head>
                <!-- write: TitleBar + Meta-Tags + CSS-Definitions -->
                <xsl:call-template name="html_head"/>
            </head>
            <body>
                <!-- write: the name of the chosen category
                     as the header of the page -->
                <xsl:call-template name="write_head">
                    <xsl:with-param name="header" select="$header"/>
                </xsl:call-template>
                <!-- write: all entries belonging to the chosen category -->

                <!-- Check if there are any entries in the chosen category: -->
                <xsl:choose>
                    <xsl:when test="($main//notstandard[@name=$catid][string()=$catid_name])">
                        <xsl:for-each select="($main//notstandard[@name=$catid][string()=$catid_name])">
                            <xsl:apply-templates select="../."/>
                        </xsl:for-each>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="document('definitions.xml')//cat_no_entry" />
                    </xsl:otherwise>
                </xsl:choose>
            </body>
            </html>
        </xsl:document>
    </xsl:for-each>
</xsl:template>    
<!-- #################### Categories Template - END ####################### -->



<!-- ###################### HTML Head_Tag - Templates ##########################
        name: html_head
        does ... generate the HTML head tag content:
                 - title bar
                 - Meta tags
                 - CSS information
     ##########################################################################
-->
<xsl:template name="html_head">
    <!-- ++++++++++ Write: titleBar of HTML-file: (optional) ++++++++++++++ -->
    <title>
        <xsl:value-of select="document('definitions.xml')//title_bar"/>
    </title>
    
    <!-- +++++++++++++++++ Set Meta Tags: (optional) ++++++++++++++++++++++ -->
    <!-- for-each loop: process all meta-tags defined in the XML file -->
    <xsl:for-each select="document('definitions.xml')//meta_tags//*">
        <meta>
            <xsl:attribute name="name">
                <xsl:value-of select="@name"/>
            </xsl:attribute>
            <xsl:attribute name="content">
                <xsl:value-of select="@content"/>
            </xsl:attribute>
        </meta>
    </xsl:for-each>
    
    <!-- +++++++++++++++++ Define CSS formats: (optional) +++++++++++++++++ -->
    <!-- First, check if there is an external CSS-file defined in definitions.xml;
         If yes, load information from the external file.
         If no, proceed with the following predefined CSS settings: -->
    <xsl:choose>
        <xsl:when test="document('definitions.xml')//css_filename !=''">
            <link rel="stylesheet" type="text/css" href="{document('definitions.xml')//css_filename}" />
        </xsl:when>
        <xsl:otherwise>
            <style type='text/css'>
                body { background-color:#ffffff; }

                .p { font-family:'Times New Roman',Times,serif; font-size:12pt;}
                
                .header { font-family:Arial, Helvetica, sans-serif; font-size:16pt; }
                .small_head { font-family:Arial, Helvetica, sans-serif; font-size:11pt; }
                
                .table_header { font-family:Arial, Helvetica, sans-serif; font-size:14pt;  }
                .table_data { font-family:Arial, Helvetica, sans-serif; font-size:12pt; }
                
                .space { font-family:Arial, Helvetica, sans-serif; font-size:5pt; }
            </style>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
<!-- ###################### HTML Head_Tag - END ########################### -->



<!-- ####################### HTML header Template ############################
        name: write_head
        does ... generate the header of the pages
     ##########################################################################
-->
<xsl:template name="write_head">
    <xsl:param name="header"/>    
    <!-- +++++++++++++++++++ Set header of HTML file: ++++++++++++++++++++ -->
    <table width="100%" border="0" cellspacing="0" cellpadding="5">
        <tr style="{concat('background-color:', document('definitions.xml')//header_row_color)}">
            <!-- Check if there is a logo defined in definitions.xml;
                 If yes, print it left from the header: -->
            <xsl:if test="document('definitions.xml')//logo !=''">
                <td width="20%" height="30" valign="middle" align="left">
                    <img src="{concat(document('definitions.xml')//pic_path, document('definitions.xml')//logo)}" alt="logo" 
/>
                </td>
            </xsl:if>
            <td width="80%" height="30" valign="middle" align="left">
                <div class="header">
                    <xsl:value-of select="$header"/>
                </div>
            </td>
            <td width="20%" height="30" valign="middle" align="right">
                <!-- the right side of the header is linked to the thematic overview-page -->
                <div class="small_head">
                    <a href="overview.html">
                        <xsl:value-of select="document('definitions.xml')//head_overview"/>
                    </a>
                </div>
            </td>
        </tr>
    </table>
    <hr />
</xsl:template>    
<!-- ##################### HTML header Template ########################## -->




<!-- ############ BIBITEM Template - Handling all Entry Fields ################
        match: bibitem
        does ... Print out every entry from the XML-file in a table:
                 left - short citation (author + year) + all linked images
                 right - entry content in Cambridge-like style.      
     ##########################################################################
-->
<xsl:template match="bibitem">
    <!-- write anker for entry: <a id="CitKey" name="CitKey"> -->
    <a>
        <xsl:attribute name="id">
            <xsl:value-of select="@label"/>
        </xsl:attribute>
        <xsl:attribute name="name">
            <xsl:value-of select="@label"/>
        </xsl:attribute>
    </a>

    <!-- set layout table for the whole HTML content:
         LEFT COLUMN: two rows (short citation + all linked images)
         RIGHT COLUMN: one row (authors + title + all other entry fields)
    -->
    <table width="100%" border="0" cellspacing="3" cellpadding="0">    
        <tr>
            <!-- left column, row #1 -->
            <td width="20%" valign="top" align="left" class="p">
                <!-- write (Citation): [ + author(s)/editor(s), <et.al,> + year + ] -->
                <xsl:text>[</xsl:text>
                <!-- Check whether author(s) or editor(s): -->
                <xsl:choose>
                    <!-- author(s) presented by the editor-field: -->
                    <xsl:when test="@type='proceedings' or @type='conference' or (@type='book' and editor) or (@type='inbook' 
and editor)">
                        <xsl:apply-templates select="editor[1]" mode="citation"/>
                    </xsl:when>
                    <!-- author(s) presented by the author-field: -->
                    <xsl:otherwise>
                        <xsl:apply-templates select="author[1]" mode="citation"/>
                    </xsl:otherwise>
                </xsl:choose>
                <xsl:text>, </xsl:text>
                <xsl:apply-templates select="year"/>
                <xsl:text>]</xsl:text>
                <br />
                
                <span class="space">&#160;<br /></span>
                
                <!-- write: linked images -->
                <!-- image #1 (linked to the BibTeX.html file (shows a single BibTeX entry)) -->
                <xsl:variable name="filename">
                    <xsl:value-of select="$bibhtml_path" />
                    <xsl:value-of select="@label" />
                </xsl:variable>
                <a>
                    <xsl:attribute name="href">
                        <xsl:value-of select="concat($filename, '.html')"/>                        
                    </xsl:attribute>
                    <img src="{concat(document('definitions.xml')//pic_path, 'bibtex.gif')}" alt="Show BibTeX entry" border="0"/>
                </a>

                <!-- image #2 (linked to the url of the postscript-file) -->
                <xsl:if test="URL">
                    <a>
                        <xsl:attribute name="href">
                            <xsl:value-of select="URL"/>
                        </xsl:attribute>
                        <img src="{concat(document('definitions.xml')//pic_path, 'ps.gif')}" alt="Download Article" border="0"/>
                    </a>
                </xsl:if>

                <!-- image #3 (linked to the url of the zipped postscript-file) -->
                <xsl:if test="notstandard[@name='urlzip']">
                    <a>
                        <xsl:attribute name="href">
                            <xsl:value-of select="notstandard[@name='urlzip']"/>
                        </xsl:attribute>
                        <img src="{concat(document('definitions.xml')//pic_path, 'ps_gz.gif')}" alt="Download Article (zipped)" border="0" />
                    </a>
                </xsl:if>

                <!-- image #4 (linked to the pdf-file of the paper) -->
                <xsl:if test="notstandard[@name='pdf']">
                    <a>
                        <xsl:attribute name="href">
                            <xsl:value-of select="notstandard[@name='pdf']"/>
                        </xsl:attribute>
                        <img src="{concat(document('definitions.xml')//pic_path, 'pdf.gif')}" alt="Download Article (pdf-file)" border="0" />
                    </a>
                </xsl:if>
                
                <!-- image #5 (linked to the html-page of the paper) -->
                <xsl:if test="notstandard[@name='urlpage']">
                    <a>
                        <xsl:attribute name="href">
                            <xsl:value-of select="notstandard[@name='urlpage']"/>
                        </xsl:attribute>
                        <img src="{concat(document('definitions.xml')//pic_path, 'html.gif')}" alt="Visit the webpage of the paper" border="0" />
                    </a>
                </xsl:if>
                
                <!-- image #6 (linked to the homepage of an author/editor) -->
                <xsl:if test="notstandard[@name='homepage']">
                    <a>
                        <xsl:attribute name="href">
                            <xsl:value-of select="notstandard[@name='homepage']"/>
                        </xsl:attribute>
                        <img src="{concat(document('definitions.xml')//pic_path, 'home.gif')}" alt="Visit the webpage of the author" border="0" />
                    </a>
                </xsl:if>
            </td>
            
            <!-- right column, row #2 -->
            <td valign="baseline" align="left" class="p">
                <!-- write: all author(s)/editor(s) + (year) --> 
                <xsl:choose>
                    <!-- editor(s) -->
                    <xsl:when test="@type='proceedings' or @type='conference' or (@type='book' and editor) or (@type='inbook' and editor)">
                        <xsl:call-template name="editor"/>
                    </xsl:when>
                    <!-- author(s) -->
                    <xsl:otherwise>
                        <xsl:apply-templates select="author/*"/>
                    </xsl:otherwise>
                </xsl:choose>
                <xsl:text> (</xsl:text>
                <xsl:apply-templates select="year"/>
                <xsl:text>).</xsl:text>
                <br />
                <!-- write: title + all other entry-fields-->
                <xsl:apply-templates select="@type"/>        
                <!-- write: description-->
                <xsl:if test="notstandard[@name='description']">
                  <br />
                    <b>Description:</b>
                    <xsl:copy-of select="notstandard[@name='description']"/>
                </xsl:if>
            </td>
        </tr>
    </table>
</xsl:template>
<!-- ###################### BIBITEM Template - End - ###################### -->



<!-- ################# BibTeX EntryType Templates Template ####################
        match: @type
        does ... force output depending on the Entry Type
     ##########################################################################
-->
<xsl:template match="@type">
    <xsl:if test="../@type='article'">
        <xsl:call-template name="Article" />
    </xsl:if>
    <xsl:if test="../@type='book'">
        <xsl:call-template name="Book" />
    </xsl:if>
    <xsl:if test="../@type='inbook'">
        <xsl:call-template name="InBook" />
    </xsl:if>
    <xsl:if test="../@type='booklet'">
        <xsl:call-template name="Booklet" />
    </xsl:if>
    <xsl:if test="../@type='incollection'">
        <xsl:call-template name="InCollection" />
    </xsl:if>
    <xsl:if test="../@type='inproceedings'">
        <xsl:call-template name="InProceedings" />
    </xsl:if>
    <xsl:if test="../@type='manual'">
        <xsl:call-template name="Manual" />
    </xsl:if>
    <xsl:if test="../@type='mastersthesis'">
        <xsl:call-template name="MastersThesis" />
    </xsl:if>
    <xsl:if test="../@type='misc'">
        <xsl:call-template name="Misc" />
    </xsl:if>
    <xsl:if test="../@type='phdthesis'">
        <xsl:call-template name="PhDThesis" />
    </xsl:if>
    <xsl:if test="../@type='proceedings' or ../@type='conference'">
        <xsl:call-template name="Proceedings" />
    </xsl:if>
    <xsl:if test="../@type='techreport'">
        <xsl:call-template name="TechReport" />
    </xsl:if>
    <xsl:if test="../@type='unpublished'">
        <xsl:call-template name="Unpublished" />
    </xsl:if>
</xsl:template>


<xsl:template name="Article">
    <xsl:apply-templates select="../title"/>
    <xsl:apply-templates select="../journal"/>
    <xsl:call-template name="vol_number"/>
    <!--<xsl:call-template name="date"/>-->
    <xsl:apply-templates select="../note"/>
</xsl:template>

<xsl:template name="Book">
    <xsl:apply-templates select="../title" mode="italic"/>
    <xsl:call-template name="vol_series"/>
    <xsl:call-template name="publ_address_ed"/>
    <!--<xsl:call-template name="date"/>-->
    <xsl:apply-templates select="../note"/>
</xsl:template>

<xsl:template name="InBook">
    <xsl:apply-templates select="../title" mode="italic"/>
    <xsl:call-template name="vol_series"/>
    <xsl:call-template name="type_chap_page"/>
    <xsl:call-template name="publ_address_ed"/>
    <!--<xsl:call-template name="date"/>-->
    <xsl:apply-templates select="../note"/>
</xsl:template>

<xsl:template name="Booklet">
    <xsl:apply-templates select="../title"/>
    <xsl:call-template name="howpubl_address"/>
</xsl:template>

<xsl:template name="InCollection">
    <xsl:apply-templates select="../title"/>
    <xsl:call-template name="editor_bookt"/>
    <xsl:call-template name="vol_series"/>
    <xsl:call-template name="type_chap_page"/>
    <xsl:call-template name="publ_address_ed"/>
    <!--<xsl:call-template name="date"/>-->
    <xsl:apply-templates select="../note"/>
</xsl:template>

<xsl:template name="InProceedings">
    <xsl:apply-templates select="../title"/>
    <xsl:call-template name="editor_bookt"/>
    <xsl:call-template name="vol_series"/>
    <xsl:call-template name="Proc_addr_page"/>
    <xsl:call-template name="Proc_org_publ"/>
    <!--<xsl:call-template name="date"/>-->
    <xsl:apply-templates select="../note"/>
</xsl:template>

<xsl:template name="Manual">
    <xsl:apply-templates select="../title" mode="italic"/>
    <xsl:call-template name="publ_address_ed"/>
    <!--<xsl:call-template name="date"/>-->
    <xsl:apply-templates select="../note"/>
</xsl:template>

<xsl:template name="MastersThesis">
    <xsl:apply-templates select="../title"/>
    <xsl:call-template name="thesis">
        <xsl:with-param name="mastersthesis" select="1"/>
    </xsl:call-template>
    <!--<xsl:call-template name="date"/>-->
    <xsl:apply-templates select="../note"/>
</xsl:template>

<xsl:template name="Misc">
    <xsl:apply-templates select="../title"/>
    <xsl:call-template name="howpubl_address"/>
    <!--<xsl:call-template name="date"/>-->
    <xsl:apply-templates select="../note"/>
</xsl:template>

<xsl:template name="PhDThesis">
    <xsl:apply-templates select="../title" mode="italic"/>
    <xsl:call-template name="thesis">
        <xsl:with-param name="phdthesis" select="1"/>
    </xsl:call-template>
    <!--<xsl:call-template name="date"/>-->
    <xsl:apply-templates select="../note"/>
</xsl:template>

<xsl:template name="Proceedings">
    <xsl:apply-templates select="../title" mode="italic"/>
    <xsl:call-template name="vol_series"/>
    <xsl:call-template name="Proc_addr_page"/>
    <xsl:call-template name="Proc_org_publ"/>
    <!--<xsl:call-template name="date"/>-->
    <xsl:apply-templates select="../note"/>
</xsl:template>

<xsl:template name="TechReport">
    <xsl:apply-templates select="../title"/>
    <xsl:call-template name="type_number"/>
    <xsl:call-template name="publ_address_ed"/>
    <!--<xsl:call-template name="date"/>-->
    <xsl:apply-templates select="../note"/>
</xsl:template>

<xsl:template name="Unpublished">
    <xsl:apply-templates select="../title"/>
    <!--<xsl:call-template name="date"/>-->
    <xsl:apply-templates select="../note"/>
</xsl:template>
<!-- ########### BibTeX EntryType Templates Template - End - ############## -->



<!-- ################## BibTeX EntryFields Templates ##########################
        match: *all entry fields*
        does ... handle all different Entry Fields
     ##########################################################################
-->
<!-- output: (Citation) author(s) -->
<xsl:template match="author" mode="citation">
    <!-- test how many authors are reported-->
    <xsl:choose>
        <!-- one author -->
        <xsl:when test="count(../author) = 1">
            <xsl:call-template name="write_content">
                <xsl:with-param name="content" select="../author/lastname"/>
            </xsl:call-template>
        </xsl:when>
        <!-- two authors -->
        <xsl:when test="count(../author) = 2">
            <xsl:call-template name="write_content">
                <xsl:with-param name="content" select="../author[1]/lastname"/>
            </xsl:call-template>
            <xsl:text> and </xsl:text>
            <xsl:call-template name="write_content">
                <xsl:with-param name="content" select="../author[2]/lastname"/>
            </xsl:call-template>
        </xsl:when>
        <!-- three or more authors -->
        <xsl:otherwise>
            <xsl:call-template name="write_content">
                <xsl:with-param name="content" select="../author[1]/lastname"/>
            </xsl:call-template>
            <xsl:text> et al.</xsl:text>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>


<!-- output: (Citation) editor(s) -->
<xsl:template match="editor" mode="citation">
    <!-- test how many editors are reported-->
    <xsl:choose>
        <!-- one editor -->
        <xsl:when test="count(../editor) = 1">
            <xsl:call-template name="write_content">
                <xsl:with-param name="content" select="../editor/lastname"/>
            </xsl:call-template>
        </xsl:when>
        <!-- two editor -->
        <xsl:when test="count(../editor) = 2">
            <xsl:call-template name="write_content">
                <xsl:with-param name="content" select="../editor[1]/lastname"/>
            </xsl:call-template>
            <xsl:text> and </xsl:text>
            <xsl:call-template name="write_content">
                <xsl:with-param name="content" select="../editor[2]/lastname"/>
            </xsl:call-template>
        </xsl:when>
        <!-- three or more editors -->
        <xsl:otherwise>
            <xsl:call-template name="write_content">
                <xsl:with-param name="content" select="../editor[1]/lastname"/>
            </xsl:call-template>
            <xsl:text> et al.</xsl:text>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>


<xsl:template match="firstname">
    <xsl:if test="1">
        <xsl:call-template name="write_content">
            <xsl:with-param name="content" select="current()"/>
        </xsl:call-template>
        <xsl:text> </xsl:text>
    </xsl:if>
</xsl:template>

<xsl:template match="middlename">
    <xsl:if test="1">
        <xsl:call-template name="write_content">
            <xsl:with-param name="content" select="current()"/>
        </xsl:call-template>
        <xsl:text> </xsl:text>
    </xsl:if>
</xsl:template>

<xsl:template match="lastname">
    <xsl:if test="1">
        <xsl:call-template name="write_content">
            <xsl:with-param name="content" select="current()"/>
        </xsl:call-template>
        <xsl:if test="position() != last()">
            <xsl:text> and </xsl:text>
        </xsl:if>
    </xsl:if>
</xsl:template>


<!-- output: month + date
     not used in this Style Sheet, but may be used in a modified version of this Style Sheet -->
<xsl:template name="date">
    <xsl:choose> <!-- test if there is a month field -->
        <xsl:when test="../month"> <!-- month + ...-->
            <xsl:text>, </xsl:text>
            <xsl:value-of select="../month"/>
            <xsl:if test="../year">
                <xsl:text> </xsl:text>
                <xsl:apply-templates select="../year"/> <!-- ... + year -->
                <xsl:text>.</xsl:text>
            </xsl:if>
        </xsl:when>
        <xsl:when test="../year and not(../month)"> <!-- only year field -->
            <xsl:text>, </xsl:text>
            <xsl:apply-templates select="../year"/>
            <xsl:text>. </xsl:text>
        </xsl:when>
    </xsl:choose>
</xsl:template>

<!-- output: editor + booktitle -->
<xsl:template name="editor_bookt">
    <xsl:choose>
        <xsl:when test="../editor"> <!-- editor + ...-->
             <xsl:call-template name="In_Editor"/>
             <xsl:if test="../booktitle">
                <xsl:apply-templates select="../booktitle" mode="withComma"/> <!-- ... + booktitle -->
            </xsl:if>
            <xsl:text>. </xsl:text>
        </xsl:when>
        <xsl:when test="../booktitle and not(../editor)"> <!-- only booktitle -->
            <xsl:apply-templates select="../booktitle"/>
            <xsl:text>. </xsl:text>
        </xsl:when>
    </xsl:choose>
</xsl:template>

<!-- output: howpublished + address -->
<xsl:template name="howpubl_address">
    <xsl:choose>
        <xsl:when test="../howpublished"> <!-- howpublished + ...-->
            <xsl:apply-templates select="../howpublished"/>
             <xsl:if test="../address">
                <xsl:apply-templates select="../address" mode="withComma"/> <!-- ... + address -->
            </xsl:if>
            <xsl:text>. </xsl:text>
        </xsl:when>
        <xsl:when test="../address and not(../howpublished)"> <!-- only address -->
            <xsl:apply-templates select="../address"/>
            <xsl:text>. </xsl:text>
        </xsl:when>
    </xsl:choose>
</xsl:template>

<!-- output: ((In)Proceedings:) address + pages -->
<xsl:template name="Proc_addr_page">
    <xsl:choose>
        <xsl:when test="../address"> <!-- address + ...-->
            <xsl:apply-templates select="../address"/>
             <xsl:if test="../pages">
                <xsl:apply-templates select="../pages" mode="withComma"/> <!-- ... + pages -->
            </xsl:if>
            <xsl:text>. </xsl:text>
        </xsl:when>
        <xsl:when test="../pages and not(../address)"> <!-- only pages -->
            <xsl:apply-templates select="../pages"/>
            <xsl:text>. </xsl:text>
        </xsl:when>
    </xsl:choose>
</xsl:template>

<!-- output: ((In)Proceedings:) organization + publisher -->
<xsl:template name="Proc_org_publ">
    <xsl:choose>
        <xsl:when test="../organization"> <!-- organization + ...-->
            <xsl:apply-templates select="../organization"/>
             <xsl:if test="../publisher">
                <xsl:text>Published by </xsl:text>
                <xsl:apply-templates select="../publisher" mode="withComma"/> <!-- ... + publisher -->
            </xsl:if>
            <xsl:text>. </xsl:text>
        </xsl:when>
        <xsl:when test="../publisher and not(../organization)"> <!-- only publisher -->
            <xsl:text>Published by </xsl:text>
            <xsl:apply-templates select="../publisher"/>
            <xsl:text>. </xsl:text>
        </xsl:when>
    </xsl:choose>
</xsl:template>

<!-- output: institution/organization/publisher + address + edition -->
<xsl:template name="publ_address_ed">
    <xsl:choose>
        <xsl:when test="(../institution or ../organization or ../publisher)"> <!-- inst/org/publ + ...-->
            <xsl:apply-templates select="../institution"/>
            <xsl:apply-templates select="../organization"/>
            <xsl:apply-templates select="../publisher"/>
             <xsl:if test="../address">
                <xsl:apply-templates select="../address" mode="withComma"/> <!-- ... + address -->
            </xsl:if>
            <xsl:if test="../edition">
                <xsl:apply-templates select="../edition" mode="withComma"/> <!-- ... + edition -->
            </xsl:if>
            <xsl:text>. </xsl:text>
        </xsl:when>
        <xsl:when test="../address and not(../institution or ../organization or ../publisher)"> <!-- address + ...-->
            <xsl:apply-templates select="../address"/>
            <xsl:if test="../edition">
                <xsl:apply-templates select="../edition" mode="withComma"/> <!-- ... + edition -->
            </xsl:if>
            <xsl:text>. </xsl:text>
        </xsl:when>
        <xsl:when test="../edition and not(../institution or ../organization or ../publisher) and not(../address)"> <!-- only 
edition -->
            <xsl:apply-templates select="../edition"/>
            <xsl:text>. </xsl:text>
        </xsl:when>
    </xsl:choose>
</xsl:template>

<!-- output: (MastersThesis/PhDThesis) type + school + address -->
<xsl:template name="thesis">
    <xsl:param name="phdthesis"/>
    <xsl:param name="mastersthesis"/>
    <xsl:if test="not(../type)"> <!-- if type field is empty write "PhD thesis"/"Masters thesis" -->
        <xsl:choose>
            <xsl:when test="$phdthesis"> <!-- PhDThesis -->
                <xsl:text>PhD thesis, </xsl:text>
            </xsl:when>
            <xsl:when test="$mastersthesis"> <!-- PhDThesis -->
                <xsl:text>Masters thesis, </xsl:text>
            </xsl:when>
        </xsl:choose>
    </xsl:if>
    <xsl:choose>
        <xsl:when test="../type"> <!-- type + ...-->
            <xsl:apply-templates select="../type"/>
             <xsl:if test="../school">
                <xsl:apply-templates select="../school" mode="withComma"/> <!-- ... + school -->
            </xsl:if>
            <xsl:if test="../address">
                <xsl:apply-templates select="../address" mode="withComma"/> <!-- ... + address -->
            </xsl:if>
            <xsl:text>. </xsl:text>
        </xsl:when>
        <xsl:when test="../school and not(../type)"> <!-- school + ...-->
            <xsl:apply-templates select="../school"/>
            <xsl:if test="../address">
                <xsl:apply-templates select="../address" mode="withComma"/> <!-- ... + address -->
            </xsl:if>
            <xsl:text>. </xsl:text>
        </xsl:when>
        <xsl:when test="../address and not(../type) and not(school)"> <!-- only address -->
            <xsl:apply-templates select="../address"/>
            <xsl:text>. </xsl:text>
        </xsl:when>
    </xsl:choose>
</xsl:template>

<!-- output: type + chapter + pages -->
<xsl:template name="type_chap_page">
    <xsl:choose>
        <xsl:when test="../type"> <!-- type + ...-->
            <xsl:apply-templates select="../type"/>
             <xsl:if test="../chapter">
                <xsl:apply-templates select="../chapter" mode="withComma"/> <!-- ... + chapter -->
            </xsl:if>
            <xsl:if test="../pages">
                <xsl:apply-templates select="../pages" mode="withComma"/> <!-- ... + pages -->
            </xsl:if>
            <xsl:text>. </xsl:text>
        </xsl:when>
        <xsl:when test="../chapter and not(../type)"> <!-- chapter + ...-->
            <xsl:value-of select="../chapter"/>
            <xsl:if test="../pages">
                <xsl:apply-templates select="../pages" mode="withComma"/> <!-- ... + pages -->
            </xsl:if>
            <xsl:text>. </xsl:text>
        </xsl:when>
        <xsl:when test="../pages and not(../type) and not(../chapter)"> <!-- only pages -->
            <xsl:apply-templates select="../pages"/>
            <xsl:text>. </xsl:text>
        </xsl:when>
    </xsl:choose>
</xsl:template>

<!-- output: (TechReport:) type + number -->
<xsl:template name="type_number">
    <xsl:choose>
        <xsl:when test="../type"> <!-- type + ...-->
            <xsl:apply-templates select="../type"/>
             <xsl:if test="../number">
                <xsl:text> Nr. </xsl:text>
                <xsl:apply-templates select="../number" mode="withComma"/> <!-- ... + number -->
            </xsl:if>
            <xsl:text>. </xsl:text>
        </xsl:when>
        <xsl:when test="../number and not(../type)"> <!-- only number -->
            <xsl:text>Technical Report Nr. </xsl:text>
            <xsl:value-of select="../number"/>
            <xsl:text>. </xsl:text>
        </xsl:when>
        <xsl:when test="not(../number) and not(../type)"> <!-- no number, no type -->
            <xsl:text>Technical Report</xsl:text>
            <xsl:text>. </xsl:text>
        </xsl:when>
    </xsl:choose>
</xsl:template>

<!-- output: (Article) volume/number -->
<xsl:template name="vol_number">
    <xsl:value-of select="../volume"/>
    <xsl:if test="../number"> <!-- test if there is a number field -->
        <xsl:text>(</xsl:text>
        <xsl:value-of select="../number"/>
        <xsl:text>)</xsl:text>
    </xsl:if>
    <xsl:if test="../pages"> <!-- test if there is a pages field -->
        <xsl:text>:</xsl:text>
        <xsl:value-of select="../pages"/>
    </xsl:if>
    <xsl:text>. </xsl:text>
</xsl:template>

<!-- output: volume/number + series -->
<xsl:template name="vol_series">
    <xsl:choose>
        <xsl:when test="(../number or ../volume)"> <!-- vol/nr + ...-->
            <xsl:text>Volume </xsl:text>
            <xsl:value-of select="../volume"/>
            <xsl:value-of select="../number"/>
            <xsl:if test="../series"> <!-- ... + series -->
                <xsl:text> of </xsl:text>
                <xsl:apply-templates select="../series" mode="italic"/>
            </xsl:if>
            <xsl:text>. </xsl:text>
        </xsl:when>
        <xsl:when test="../series and not(../number or ../volume)"> <!-- only series -->
            <xsl:apply-templates select="../series" mode="italic"/>
            <xsl:text>. </xsl:text>
        </xsl:when>
    </xsl:choose>
</xsl:template>

<xsl:template match="address" mode="withComma">
    <xsl:text>, </xsl:text>
    <xsl:call-template name="write_content">
        <xsl:with-param name="content" select="current()"/>
    </xsl:call-template>
</xsl:template>

<xsl:template match="booktitle" mode="withComma">
    <xsl:text>, </xsl:text>
    <em>
        <xsl:call-template name="write_content">
            <!-- replace two short dashes '-' with one long dash -->
            <xsl:with-param name="content" select="translate(current(), '--', '-')"/>
        </xsl:call-template>
    </em>
</xsl:template>
<xsl:template match="booktitle">
    <xsl:text>In: </xsl:text>
    <em>
        <xsl:call-template name="write_content">
            <!-- replace two short dashes '-' with one long dash -->
            <xsl:with-param name="content" select="translate(current(), '--', '-')"/>
        </xsl:call-template>
    </em>
</xsl:template>

<xsl:template match="chapter" mode="withComma">
    <xsl:text> </xsl:text>
    <xsl:call-template name="write_content">
        <xsl:with-param name="content" select="current()"/>
    </xsl:call-template>
</xsl:template>

<xsl:template match="edition">
    <xsl:call-template name="write_content">
        <xsl:with-param name="content" select="current()"/>
    </xsl:call-template>
    <xsl:text> edition</xsl:text>
</xsl:template>
<xsl:template match="edition" mode="withComma">
    <xsl:text>, </xsl:text>
    <xsl:call-template name="write_content">
        <xsl:with-param name="content" select="current()"/>
    </xsl:call-template>
    <xsl:text> edition</xsl:text>
</xsl:template>

<xsl:template name="editor">
    <xsl:apply-templates select="editor/*"/>
    <xsl:text> (</xsl:text>
    <xsl:choose> <!-- test number of editors and write either "(ed.)" or "(eds.)" -->
        <xsl:when test="count(editor) &gt; 1"> <!-- two or more editors -->
            <xsl:text>eds.</xsl:text>
        </xsl:when>
        <xsl:otherwise> <!-- just one editor -->
            <xsl:text>ed.</xsl:text>
        </xsl:otherwise>
    </xsl:choose>
    <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template name="In_Editor">
    <xsl:text>In: </xsl:text>
    <xsl:apply-templates select="../editor/*"/>
    <xsl:text> (</xsl:text>
    <xsl:choose> <!-- test number of editors and write either "(ed.)" or "(eds.)" -->
        <xsl:when test="count(../editor) &gt; 1"> <!-- two or more editors -->
            <xsl:text>eds.</xsl:text>
        </xsl:when>
        <xsl:otherwise> <!-- just one editor -->
            <xsl:text>ed.</xsl:text>
        </xsl:otherwise>
    </xsl:choose>
    <xsl:text>)</xsl:text>
</xsl:template>
    
<xsl:template match="howpublished">
    <xsl:call-template name="write_content">
        <!-- replace two short dashes '-' with one long dash -->
            <xsl:with-param name="content" select="translate(current(), '--', '-')"/>
    </xsl:call-template>
</xsl:template>

<xsl:template match="institution">
    <xsl:call-template name="write_content">
        <xsl:with-param name="content" select="current()"/>
    </xsl:call-template>
</xsl:template>

<xsl:template match="journal">
    <xsl:text>In: </xsl:text>
    <em>
        <xsl:call-template name="write_content">
            <xsl:with-param name="content" select="current()"/>
        </xsl:call-template>
    </em>
    <xsl:text>, </xsl:text>
</xsl:template>

<xsl:template match="note">
    <xsl:if test="../note">
        <xsl:text> </xsl:text>
        <xsl:call-template name="write_content">
            <!-- replace two short dashes '-' with one long dash -->
            <xsl:with-param name="content" select="translate(current(), '--', '-')"/>
        </xsl:call-template>
        <xsl:text>.</xsl:text>
    </xsl:if>
</xsl:template>

<xsl:template match="organization">
    <xsl:call-template name="write_content">
        <xsl:with-param name="content" select="current()"/>
    </xsl:call-template>
</xsl:template>

<xsl:template match="pages">
    <xsl:text>pp. </xsl:text>
    <!-- replace two short dashes '-' with one long dash -->
    <xsl:value-of select="translate(current(),'--','-')"/>
</xsl:template>
<xsl:template match="pages" mode="withComma">
    <xsl:text>, pp. </xsl:text>
    <xsl:value-of select="translate(current(),'--','-')"/>
</xsl:template>

<xsl:template match="publisher" mode="withComma">
    <xsl:text>, </xsl:text>
    <xsl:call-template name="write_content">
        <xsl:with-param name="content" select="current()"/>
    </xsl:call-template>
</xsl:template>
<xsl:template match="publisher">
    <xsl:call-template name="write_content">
        <xsl:with-param name="content" select="current()"/>
    </xsl:call-template>
</xsl:template>

<xsl:template match="series" mode="italic">
    <em>
        <xsl:call-template name="write_content">
            <!-- replace two short dashes '-' with one long dash -->
            <xsl:with-param name="content" select="translate(current(), '--', '-')"/>
        </xsl:call-template>
    </em>
</xsl:template>

<xsl:template match="school" mode="withComma">
    <xsl:text>, </xsl:text>
    <xsl:call-template name="write_content">
        <xsl:with-param name="content" select="current()"/>
    </xsl:call-template>
</xsl:template>

<!-- output: title + CR-->
<xsl:template match="title">
    <xsl:call-template name="write_content">
        <!-- replace two short dashes '-' with one long dash -->
        <xsl:with-param name="content" select="translate(current(), '--', '-')"/>
    </xsl:call-template>
    
    <!-- Check, whether the current field contains a '?' or '!'
         case false, print a full stop at the end of the output: -->
    <xsl:if test="substring(translate(current(), '{}', ''), string-length(translate(current(), '{}', '')), 1) != '!' and substring(translate(current(), '{}', ''), string-length(translate(current(), '{}', '')), 1) != '?'">
            <xsl:text>.</xsl:text>
    </xsl:if>
    <br />
</xsl:template>

<xsl:template match="title" mode="italic">
    <em>
        <xsl:call-template name="write_content">
            <!-- replace two short dashes '-' with one long dash -->
            <xsl:with-param name="content" select="translate(current(), '--', '-')"/>
        </xsl:call-template>
    </em>
    <!-- Check, whether the current field contains a '?' or '!'
         case false, print a full stop at the end of the output: -->
    <xsl:if test="substring(translate(current(), '{}', ''), string-length(translate(current(), '{}', '')), 1) != '!' and substring(translate(current(), '{}', ''), string-length(translate(current(), '{}', '')), 1) != '?'">
            <xsl:text>.</xsl:text>
    </xsl:if>
    <br />
</xsl:template>

<xsl:template match="type">
    <xsl:call-template name="write_content">
        <xsl:with-param name="content" select="current()"/>
    </xsl:call-template>
</xsl:template>

<xsl:template match="year">
    <xsl:apply-templates/>
</xsl:template>
<!-- ################# BibTeX EntryFields Templates - END ################# -->



<!-- ######################## WriteContent Template ###########################
        name: write_content
        does ... Check if there are any 'unrecognized' special characters;
                 if yes, these characters (like \'{o}) will be deleted.
                 Check if the current field contains an abbreviation;
                 if yes, replace the abbreviation with its complete content,
                 if no, just write the content. 
     ##########################################################################
-->
<xsl:template name="write_content">
    <xsl:param name="content"/>
   
    <!-- Check, whether the current field contains an abbreviation -->
    <xsl:choose>
        <!-- yes, current field contains an abbreviation (@string or @macro)-->
        <xsl:when test="./abbrev">
            <xsl:variable name="tmp" select="./abbrev/@alias"/>
            <xsl:value-of select="//macro[@alias=$tmp]"/>
        </xsl:when>
        <xsl:otherwise>
        <!-- no, current field contains NO abbreviation-->
            <!-- delete additional brackets "{}" inside the text (if there are any) -->
            <xsl:value-of select="translate($content, '{}', '')"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
<!-- ################### WriteContent Template - END - #################### -->






<!-- #################### Thematic Overview Template ##########################
        name: gen_cat_sorted
        does ... generate a single HTML file which presents all thematic categories,
                 linked to the corresponding HTML files
     ##########################################################################
-->
<xsl:template name="gen_overview">
    <xsl:document href="overview.html" format="htmlFormat">
        <html> 
        <head>
            <!-- write: TitleBar + Meta-Tags + CSS-Definitions -->
            <xsl:call-template name="html_head"/>
        </head>
        <body>
        
            <!-- write header: -->
            <table width="100%" border="0" cellspacing="0" cellpadding="5">
                <!-- set the background-color of the header row: -->
                <tr style="{concat('background-color:', document('definitions.xml')//header_row_color)}">
                    <!-- Check if there is a logo defined in definitions.xml;
                         If yes, print it left of the header: -->
                    <xsl:if test="document('definitions.xml')//logo !=''">
                        <td width="20%" height="30" valign="middle" align="left">
                            <img src="{concat(document('definitions.xml')//pic_path, document('definitions.xml')//logo)}" 
alt="logo" />
                        </td>
                    </xsl:if>
                    <!-- write: header of page -->
                    <td width="80%" height="30" valign="middle" align="left" class="header">
                        <xsl:value-of select="document('definitions.xml')//head_overview"/>
                    </td>
                    <!-- write: link (back to prevous page) -->
                    <td width="20%" height="30" valign="middle" align="right" class="small_head">
                        <a href="list.html">
                            <xsl:value-of select="document('definitions.xml')//head_list"/>
                        </a>
                    </td>
                </tr>
            </table>
            <hr /><br />

            <!-- write TableData - START - *************************************** -->
            <table cellspacing="2" cellpadding="4" border="1" width="100%">
                <!-- Table row #1: Main-Categories -->
                <tr style="background-color:#c7c7c7;">
                    <xsl:for-each select="document('definitions.xml')//category">
                        <td align="left" valign="top">
                            <!-- use additional table for better layout -->
                            <table border="0">
                                <tr style="background-color:#c7c7c7;">
                                    <td align="right" valign="top" class="table_header">
                                        <xsl:call-template name="write_level_id"/>
                                    </td>
                                    <td align="left" valign="top" class="table_header">
                                        <xsl:call-template name="write_name_link"/>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </xsl:for-each>
                </tr>
                
                <!-- Table row #2: if there are any Sub-Categories - write them -->
                <tr style="background-color:#fafafa;">
                    <xsl:if test="document('definitions.xml')//category/subcat">
                        <xsl:call-template name="subcat_loop"/>
                    </xsl:if>
                </tr>
            </table>
            <!-- write TableData - END - ************************************** -->
        </body>
        </html>
    </xsl:document>
</xsl:template>

<xsl:template name="subcat_loop">
        <!-- loop_1: call main-category: -->
        <xsl:for-each select="document('definitions.xml')//category">
            <td align="left" valign="top">
                <!-- Check if there are any sub-categories of the chosen main-category;
                     if no, just print the whitespace character (&#160;) inside <td>;
                     if yes, proceed all sub-categories -->
                <xsl:choose>
                    <xsl:when test="count(./*) = 0">
                        &#160;
                    </xsl:when>
                    <xsl:otherwise>
                        <!-- loop_2: call all sub-categories of the chosen main-category -->
                        <xsl:for-each select=".//*">        
                            <!-- use additional table for better layout -->
                            <table border="0" cellspacing="{document('definitions.xml')//line_height}" cellpadding="0">
                                <tr>
                                    <!-- set the table indent: -->
                                    <xsl:variable name="level_id">
                                        <xsl:value-of select="string-length(translate(@id, '.', ''))"/>
                                    </xsl:variable>
                                    <xsl:if test="document('definitions.xml')//table_indent[@level_id=$level_id][@value != 
'0']">
                                        <td align="right" valign="top" class="table_data" 
width="{number(document('definitions.xml')//table_indent[@level_id=$level_id]/@value)}">
                                            &#160;
                                        </td>
                                    </xsl:if>
                                    
                                    <!-- write level_id & category_name: -->
                                    <td align="right" valign="top" class="table_data">
                                        <xsl:call-template name="write_level_id"/>
                                    </td>
                                    <td align="left" valign="top" class="table_data">
                                    <xsl:call-template name="write_name_link"/>
                                    </td>
                                    
                                </tr>
                            </table>
                        </xsl:for-each>
                    </xsl:otherwise>
                </xsl:choose>
            </td>
        </xsl:for-each>
</xsl:template>

<!-- write: level-id -->
<xsl:template name="write_level_id">
    <xsl:value-of select="@id"/>
    <xsl:text>) </xsl:text>
</xsl:template>

<!-- write: subject-name and link it to the correponding HTML-file -->
<xsl:template name="write_name_link">
    <a>
        <xsl:attribute name="href">
            <xsl:value-of select="@catid"/>
            <xsl:text>.html</xsl:text>
        </xsl:attribute>
        <xsl:value-of select="@name"/>
    </a>            
</xsl:template>
<!-- ############### Thematic Overview Template - END - ################### -->

</xsl:stylesheet>

